﻿using Etapa1.Objects;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using PloobsEngine;
using PloobsEngine.Cameras;
using PloobsEngine.Entity;
using PloobsEngine.Input;
using PloobsEngine.Light;
using PloobsEngine.Material;
using PloobsEngine.Modelo;
using PloobsEngine.Physics;
using PloobsEngine.Physics.Bepu;
using PloobsEngine.SceneControl;
using PloobsEngine.Trigger;
using PloobsEngineDemo3;
using PloobsEngine.Draw;
using PloobsEngine.MessageSystem;

namespace Etapa1.Screens
{   
    /// <summary>
    /// Env Map Screen    
    /// </summary>
    public class EnvMapScreen : SceneScreen
    {
        private BepuPhysicWorld physicWorld;
        private BrutalForceWorld mundo;
        private EngineStuff engine;
        ICamera cam;

        public EnvMapScreen(EngineStuff es)
        {
            this.engine = es;
            physicWorld = new BepuPhysicWorld();
            mundo = new BrutalForceWorld(physicWorld);
        }

        public override void LoadContent(EngineStuff es)
        {
            ///Adicionando Componente de Input 
            ///Utilizado pelo "Atirador de bolas"
            InputAdvanced inp = new InputAdvanced(es);
            engine.AddComponent(inp);

            base.LoadContent(es);



            #region Models
            {                
                SimpleModel sm = new SimpleModel("..\\Content\\Model\\cilos", "..\\Content\\Textures\\white");
                sm.LoadModelo();             
                TriangleMeshObject tm = new TriangleMeshObject(new Vector3(200, 5, 0), sm);
                ///Environment Map Shader
                ///Eh possivel misturar a textura diffuse passada com o environment map, basta configurar adequadamente o shader
                EMReflective shader = new EMReflective("Textures\\cubeMap", ReflectionType.PerfectMirror);
                shader.Initialize();
                IMaterial mat = new Material(shader);
                IObject obj3 = new SimpleObject(mat, tm, sm);
                mundo.AddObject(obj3);      
     
            }


            ///Cenario de sempre
            {
                SimpleModel sm = new SimpleModel("..\\Content\\Model\\cenario");
                sm.LoadModelo();
                IPhysicObject pi = new TriangleMeshObject(Vector3.Zero, sm);
                CustomDeferred shader = new CustomDeferred(false, false, false, false);
                shader.SpecularIntensity = 0;
                shader.SpecularPower = 0;
                shader.Initialize();
                IMaterial mat = new Material(shader);
                IObject obj3 = new SimpleObject(mat, pi, sm);
                mundo.AddObject(obj3);
            }


            #endregion

            cam = new CameraFirstPerson(true);
            cam.FarPlane = 2000;

            LightThrowBepu lt = new LightThrowBepu(mundo, engine);

            #region NormalLight
            DirectionalLight ld1 = new DirectionalLight(Vector3.Left, Color.White);
            DirectionalLight ld2 = new DirectionalLight(Vector3.Right, Color.White);
            DirectionalLight ld3 = new DirectionalLight(Vector3.Backward, Color.White);
            DirectionalLight ld4 = new DirectionalLight(Vector3.Forward, Color.White);
            DirectionalLight ld5 = new DirectionalLight(Vector3.Down, Color.White);
            float li = 0.4f;
            ld1.LightIntensity = li;
            ld2.LightIntensity = li;
            ld3.LightIntensity = li;
            ld4.LightIntensity = li;
            ld5.LightIntensity = li;
            mundo.AddLight(ld1);
            mundo.AddLight(ld2);
            mundo.AddLight(ld3);
            mundo.AddLight(ld4);
            mundo.AddLight(ld5);
            #endregion

            ////Criacao de uma Tecnica
            DeferredRenderTechnic dr = new DeferredRenderTechnic(engine);

            IRenderTechnic[] rt = new IRenderTechnic[] { dr };
            this.RenderTechnics = rt;
            mundo.AddCamera(cam);
            this.World = mundo;

            AntiAliasingPostEffect aa = new AntiAliasingPostEffect();
            aa.Weight = 16;            
            dr.AddPostEffect(aa);
        }
    }

    
}

